package com.mvc.servlet;

import com.mvc.pojo.Teacher;
import com.mvc.service.TeacherService;
import com.mvc.service.impl.TeacherServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAllServlet")
public class FindAllServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TeacherService teacherService = new TeacherServiceImpl();
        List<Teacher> allTeacher = teacherService.findAllTeacher();

        //验证是否收到数据
        //for (Teacher teacher : allTeacher) {
        //    System.out.println(teacher);
        //}

        //将数据存到域中
        request.setAttribute("allTeacher", allTeacher);

        //进行转发
        request.getRequestDispatcher("jsp/show.jsp").forward(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
